<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*"  %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="elibrary.DaoConnection"%>
<%@ include file="config.jsp" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">


    </head>
    <body>
        <% response.setDateHeader("Expires",-1);

        try{
	
		
		
                        String responseText=new String("");
                        String search=(String) request.getParameter("search");
                        String type=(String) request.getParameter("type");
 
		
                        //connection is made to the database
		
                    Connection con = DaoConnection.getcon(connectURL, DBuser, DBpass);
                        String query;
                        ResultSet rs=null;
                        PreparedStatement ps=null;
                        query="select * from book where UPPER("+type+") like '%"+search.toUpperCase()+"%'";
                        ps=con.prepareStatement(query);
                        rs=ps.executeQuery();
		
                        //if the book is not found in the database
		
                        if(rs.next() == false)
                                responseText+="<p>Book Not Found!</p>";
                        else{
                                responseText=new String("<table class="+'"'+"browsebooks"+'"'+">");
                                do
                                {	responseText+="<tr>";
                                        responseText+="<td style="+'"'+"width:82px;"+'"'+"><a href="+'"'+"viewBook.jsp?id="+rs.getString("BOOKID")+'"'+">"+rs.getString("BOOKID")+"</a></td>";
                                        responseText+="<td style="+'"'+"width:110px"+'"'+">"+rs.getString("BOOKNAME")+"</td>";
                                        responseText+="<td style="+'"'+"width:82px"+'"'+">"+rs.getString("AUTHOR")+"</td>";
                                        responseText+="<td style="+'"'+"width:82px;"+'"'+">"+rs.getString("SUBJECT")+"</td>";
                                        responseText+="<td style="+'"'+"width:82px"+'"'+">"+rs.getString("CATEGORY")+"</td>";
                                        responseText+="<td style="+'"'+"width:110px;"+'"'+">"+rs.getString("TAGS")+"</td>";
                                        responseText+="</tr>";
                                }while(rs.next());
                                responseText+="</table>";
                        }
			
                out.print(responseText);
                rs.close();
                con.close();
		 
         }
         catch(Exception e)
                {
                        out.println("Error "+e.getMessage());
		
                }
	
        %>
    </body>
</html>
